package diagramobjects;
import java.awt.Graphics;
import java.util.Vector;

import program.PaintObjects;
import utils.Color;
import utils.Point;


public class UseCase extends DiagramObject {
	
	protected Integer Id;
	protected Point Position;
	protected Integer Width;
	protected Integer Height;
	protected Text UseCaseName;
	
	
	@Override
	/**
	 * uzywana do rysowania linii na panelu - wywolywana w Drawing Panel
	 */
	public void Draw(Graphics g, PaintObjects po) 
	{
		po.DrawUseCase(g, this);
	}

	@Override
	public void DrawSelection(Graphics g, PaintObjects po)
	{
		// TODO Auto-generated method stub
		po.DrawUseCaseSelection(g, this);
	}
	
	/*public Integer getId() {
		return Id;
	}
*/
	
	
	/*public Integer getPositionX() {
		return PositionX;
	}

	public Integer getPositionY() {
		return PositionY;
	}*/

	public Integer getWidth() {
		return Width;
	}

	public Integer getHeight() {
		return Height;
	}

	public String getUseCaseName() {
		return UseCaseName.getCaption();
	}
	
	public UseCase(Integer posX, Integer posY, Integer wid, Integer hei, String name, Integer nameSize) {
		super();
		Id = 0;
		Position = new Point(posX, posY);
		Width = wid;
		Height = hei;
		Double posx = posX + Width/2 - name.length()*10*0.275;
		Double posy = posY + Height/2 +10*0.4;
		UseCaseName = new Text(name,new Point(posx.intValue(), posy.intValue()), new Color(0,255,0), 10);
	
		System.out.println("Creating UseCase");
		Print();
		
	}
	
	
	
	@Override
	public Integer getPositionX()
	{
		return Position.getX();
	}

	@Override
	public Integer getPositionY()
	{
		return Position.getY();
	}

	public void SetSize(Integer w, Integer h)
	{
		Double posx = Position.getX() + Width/2 - UseCaseName.getCaption().length()*UseCaseName.getTextSize()*0.275;
		Double posy = Position.getY() + Height/2 +UseCaseName.getTextSize()*0.4;
		
		Width = w;
		Height = h;
		UseCaseName.MoveTo(posx.intValue(), posy.intValue());
	}
	
	
	/**
	 * przesuwa UseCase do wybranej lokalizacji
	 * @param x
	 * @param y
	 */

	/*public void MoveTo(Integer x, Integer y)
	{
		Position.MoveTo(x, y);
		
	}*/
	
	/**
	 * przesuwa UseCase do wybranej lokalizacji
	 * @param x
	 * @param y
	 */
	
	/**
	 * sluzy zapisaniu danych do bazy danych - zwraca fragment potrzebnego zapytania
	 * @return
	 */
	public String ToDatabase()
	{
		
		String toReturn = /* Id.toString() + "," +*/
			Position.getX().toString() + "," +
			Position.getY().toString() + "," +
			Width.toString() + "," +
			Height.toString() + ",'" +
			UseCaseName.toString() ;
		
		return toReturn;
		
	}
	
	/**
	 * drukuje istniejacy UseCase - DO TESTOW
	 */
	
	public void Print()
	{
		String toReturn = Id.toString() + "," +
			Position.getX().toString() + "," +
			Position.getY().toString() + "," +
			Width.toString() + "," +
			Height.toString() + "," +
			UseCaseName.toString();

		System.out.println("PRINTING USECASE " + toReturn);
	}

	
	
	public Integer getUseCaseNameSize() {
		return UseCaseName.getTextSize();
	}

	public void SetTextSize(Integer size)
	{
		UseCaseName.setTextSize(size);
		
	}

	
	
/*	@Override
	public Boolean Selection(Vector<Point> SelectionCorners)
	{
		//System.out.println("ACTOR SELECTION");
		Integer tmpBX = getPositionX();
		Integer tmpBY = getPositionY();
		Integer tmpEX = tmpBX + getWidth();
		Integer tmpEY = tmpBY + getHeight();
		
		
		
		for (int i = 0; i < SelectionCorners.size(); ++i)
		{
			
			System.out.println("SelectionCorners: " + i + "-szy x: " + SelectionCorners.get(i).getX() + " y: " + SelectionCorners.get(i).getY());
			
			System.out.println(SelectionCorners.get(i).getX() + " > " + tmpBX);
			System.out.println(SelectionCorners.get(i).getX() + " < " + tmpEX);
			System.out.println(SelectionCorners.get(i).getY() + " > " + tmpBY );
			System.out.println(SelectionCorners.get(i).getY() + " < " + tmpEY);
			
			if (  ( (SelectionCorners.get(i).getX() > tmpBX ) && (SelectionCorners.get(i).getX() < tmpEX) )
				&& ( (SelectionCorners.get(i).getY() > tmpBY ) && (SelectionCorners.get(i).getY() < tmpEY) )  )
			{
				System.out.println("ACTOR ----->>>>>>> SELECTED!!!!!");
				return true;
			}

			
		}
			
		return false;
	}*/
	
	@Override
	public Boolean Selection(Integer selLeft, Integer selRight, Integer selTop, Integer selBottom)
	{	
		
		//System.out.println("ACTOR SELECTION");
		Integer Left = getPositionX();
		Integer Right = getPositionX() + getWidth();
		Integer Top = getPositionY();
		Integer Bottom = getPositionY() + getHeight();

			
		return (Left < selRight) && 
					(Right > selLeft) &&
					(Top < selBottom) &&
					(Bottom > selTop);
					
	}

/*	public Boolean PointCollision(Integer x, Integer y)
	{
		return false;
	}
*/
	@Override
	public void MoveByVector(Integer vx, Integer vy)
	{
		Position.MoveByVector(vx, vy);
		UseCaseName.MoveByVector(vx, vy);
	}	

	
	
}
